package com.dounine.clouddisk360.parser.deserializer.authtoken;

import java.io.IOException;
import java.net.URISyntaxException;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.protocol.HttpContext;

import com.dounine.clouddisk360.exception.CloudDiskException;
import com.dounine.clouddisk360.parser.deserializer.BaseConst;
import com.dounine.clouddisk360.parser.deserializer.BaseRequestInterceptor;
import com.dounine.clouddisk360.parser.deserializer.MsgConst;

public class AuthTokenRequestInterceptor extends BaseRequestInterceptor implements HttpRequestInterceptor{
	
	private AuthTokenConfig authTokenConfig;
	public AuthTokenRequestInterceptor(AuthTokenConfig authTokenConfig) {
		this.authTokenConfig = authTokenConfig;
	}

	@Override
	public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
		super.process(request, context);
		if(null==context.getAttribute(BaseConst.REQUEST_HOST_NAME)){
			throw new CloudDiskException(MsgConst.HOST_VALUE_NOT_NULL);
		}else{
			request.addHeader(AuthTokenConst.HOST_KEY, String.valueOf(context.getAttribute(BaseConst.REQUEST_HOST_NAME)));
		}
		request.addHeader(AuthTokenConst.REFERER_KEY, AuthTokenConst.REFERER_VAL);
	}

}
